<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>
<%@ page import="org.edu.system.DBConnect" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>  </title>
</head>
<body>
	<%
	String driverName = "com.mysql.jdbc.Driver";
	   String userName = "root";
	   String userPwd = "123456";
	   String dbName = "Sa";
	   String url1="jdbc:mysql://localhost:3306/"+dbName;
	   String url2="?user="+userName+"&password="+userPwd;
	   String url3="&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC";
	   String url =url1+url2+url3;
	   Connection conn = DBConnect.getCon();
	   
	   String sql="update teacher set tc_passwd=? where tc_id=?";
	   PreparedStatement pstmt = conn.prepareStatement(sql);
	   request.setCharacterEncoding("utf-8");//设置字符编码，避免出现乱吗
	   String tc_npasswd_1 = request.getParameter("tc_npasswd_1");
	   String tc_npasswd_2 = request.getParameter("tc_npasswd_2");
	   String tc_id = request.getParameter("tc_id");
	   
	   
	   
	   		if(!tc_npasswd_1.equals(tc_npasswd_2))
	   		{	       
		       	out.println("<html><body>");
		       	out.println("<h2>两次密码输入不一致，密码修改失败！<br></h2>");
		       	out.println("<a href='javascript:history.back(-1)''>返回上一页</a>");
		       	out.println("</body></html>");
       			return;
       		}
            else if(tc_npasswd_1.length()<3&&tc_npasswd_1.length()>32)
            {
	    		out.println("<html><body>");
		       	out.println("<h2>密码长度不能少于3位数<br></h2>");
		       	out.println("<a href='javascript:history.back(-1)''>返回上一页</a>");
		       	out.println("</body></html>");
		       	return;
             }
            else
				 { pstmt.setString(1,tc_npasswd_1);}
		
	   
	   pstmt.setString(2,tc_id);
		  
	   
	   
	   
	   try{
		   int n = pstmt.executeUpdate();
		   if(n>=1){%>
		   修改成功!<br><a href='javascript:history.back(-1)''>返回</a>
		   <%}
		   else{%>
		   修改失败!<%=n%><br><a href="javascript:history.go(-1);location.reload()">返回</a>
		   <%}
		   }catch(Exception e){%>
		   修改过程出现异常错误!<br><a href="javascript:history.go(-1);location.reload()">返回</a>
		   <%=e.getMessage() %>
		   <%
		   }
	   if(pstmt!=null){}
	   if(conn!=null){}
	%>
</body>
</html>